package no.knowit.eventorama.dao;

import java.util.List;

import javax.jdo.PersistenceManager;

import no.knowit.eventorama.dataobject.Event;

public class EventDAO {

	protected PersistenceManager pm;

	public EventDAO() {
		pm = PMF.get().getPersistenceManager();
	}

	@SuppressWarnings("unchecked")
	public List<Event> loadAll() {
		String query = "select from " + Event.class.getName();
		List<Event> results = (List<Event>) pm.newQuery(query).execute();
		return results;
	}

	public Event loadByKey(long id) {
		return pm.getObjectById(Event.class, new Long(id));
	}

	public void removeById(long id) {
		pm.deletePersistent(loadByKey(id));
	}

	public void save(Object o) {
		pm.makePersistent(o);
	}

	public void close() {
		pm.close();
	}

}
